package com.cl.it.custom.controller;


import com.cl.it.custom.model.NewsVo;
import com.cl.it.custom.service.IBizNewsService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * <p>
 * 新闻 前端控制器
 * </p>
 *
 * @author kehui
 * @since 2022-01-17
 */
@Controller
@RequestMapping("/custom/core/news")
public class BizNewsController {

    @Autowired
    private IBizNewsService newsService;

    @RequestMapping("/page")
    public ModelAndView page(String companyName, Integer curPage, Integer pagesize) {
        ModelAndView mav = new ModelAndView("page/articles");
        IPage<NewsVo> ipage = newsService.page(companyName, curPage, pagesize);
        mav.addObject("pageobj", ipage);
        mav.addObject("companyName", companyName);
        return mav;
    }

    @RequestMapping("/articles")
    public ModelAndView articles(String companyName) {
        ModelAndView mav = new ModelAndView("page/articles");
        mav.addObject("companyName", companyName);
        return mav;
    }

    @RequestMapping("/article_detail")
    public ModelAndView articleDetail(long id) {
        ModelAndView mav = new ModelAndView("page/article_detail");
        mav.addObject("id", id);
        return mav;
    }

    @RequestMapping("/pageAjax")
    @ResponseBody
    public IPage<NewsVo> pageAjax(String companyName, Integer curPage, Integer pagesize) {
        IPage<NewsVo> ipage = newsService.page(companyName, curPage, pagesize);
        return ipage;
    }

    @RequestMapping("/article")
    @ResponseBody
    public NewsVo article(Long id) {
        return newsService.news(id);
    }

}

